package com.bmslz.monitor.base.factory;

import com.bmslz.monitor.service.RuleDataCompare;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 告警规则数据比对工厂
 */
@Service
public class RuleDataCompareFactory {

    private final List<RuleDataCompare> strategies;

    @Autowired
    public RuleDataCompareFactory(List<RuleDataCompare> strategies) {
        this.strategies = strategies;
    }

    /**
     * 根据数据类型获取对应实现
     * @param dataType 数据类型 1数值 2日期yyyy-MM-dd 3 日期yyyy-MM-dd HH:mm:ss
     * @return
     */
    public RuleDataCompare getStrategy(String dataType) {
        return strategies.stream()
                .filter(s -> s.supports(dataType))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unsupported data type: " + dataType));
    }
}
